-- GuideSlimeDisplay
-- Created by zouyb
-- 负责引导冈布奥外观显示

require "game/ui/module/guide/GuideSlimeAnimation"

-- 引导冈布奥的相关配置
-- TODO 从配置表读取
local configList = {
	{ name = "effect_anim/adv_talk", idle_frame_start = 1, idle_frame_end = 23, talk_frame_start = 24, talk_frame_end = 45, speed = 0.2, offset = cc.p(-480, 698) },
	{ name = "effect_anim/adv_talk2", idle_frame_start = 1, idle_frame_end = 23, talk_frame_start = 24, talk_frame_end = 45, speed = 0.2, offset = cc.p(-480, 698) },
	{ name = "effect_anim/brave_talk", idle_frame_start = 1, idle_frame_end = 23, talk_frame_start = 24, talk_frame_end = 45, speed = 0.2, offset = cc.p(-480, 698) },
    { name = "effect_anim/newbie_talk3", idle_frame_start = 1, idle_frame_end = 23, talk_frame_start = 24, talk_frame_end = 45, speed = 0.2, offset = cc.p(-480, 698) },
};

-- GuideSlimeDisplay继承自Node
GuideSlimeDisplay = class("GuideSlimeDisplay", function()
    return cc.Node:create();
end);

function GuideSlimeDisplay.create(showType)
    return GuideSlimeDisplay.new(showType);
end

-- 构造函数
function GuideSlimeDisplay:ctor(showType)
    self:setName("GuideSlimeDisplay");

    -- 创建动画
    local config = configList[showType];
    local animation = GuideSlimeAnimation.create(config.name .. ".csb");
    animation.node:setPosition(config.offset);

    self.animation = animation;
    self:addChild(animation);

	self.config = config;

    -- 默认播放待机动作
    self:gotoIdle();

    self:registerScriptHandler(function(ev)
        if ev == "exitTransitionStart" then
            if self.animation.action then
                self.animation.action:clearFrameEventCallFunc();
            end

            self.animation:destroy();
        end
    end);
end

-- 播放待机动作
function GuideSlimeDisplay:gotoIdle()
    -- 播放
    self.animation:play(true, self.config.idle_frame_start, self.config.idle_frame_end, self.config.speed);
end

-- 播放说话动作
function GuideSlimeDisplay:gotoTalk()
    -- 播放
    self.animation:play(true, self.config.talk_frame_start, self.config.talk_frame_end, self.config.speed);
end



